package categoryModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import parameter.Path;
import functions.FileFunction;
import functions.TermFunction;
import modules.*;

public class GenWikiCFMain {
	public static void main(String args[]) throws Exception{
		
		Wikimap wikimap = new Wikimap();
		
		String sourcePath = Path.CATEGORY_MODEL_TFIDF_PATH;
		String targetPath = Path.CATEGORY_MODEL_WIKI_CF_PATH;
		
		Map<String, Map<String,Double>> TFIDF_Map = FileFunction.readMapStr_StrDou(sourcePath);
		Map<String, Map<String,Double>> WIKI_CF_Map = new HashMap<String, Map<String, Double>>();
		
		for (Entry<String, Map<String, Double>> entry : TFIDF_Map.entrySet()) {
			String key = entry.getKey();
			System.out.println("Loading "+key);
			Map<String,Double> categoryMap = new HashMap<String,Double>();
			
			Map<String, Double> value = entry.getValue();
			for (Entry<String, Double> entry2 : value.entrySet()) {
				String key2 = entry2.getKey();
				Double value2 = entry2.getValue();
				// TFIDF to WIKI-Category conversion method -----------------------
				List<String> categoryList = wikimap.getCategory(key2);
				for( String str : categoryList ){
					//if(str.contains("년")) continue;
					if(categoryMap.containsKey(str)){
						categoryMap.put(str, categoryMap.get(str) + value2);
					}else{
						categoryMap.put(str, value2);
					}
				}
				//  -------------------------------------------------------
			}
			WIKI_CF_Map.put(key, categoryMap);
		}
		
		FileFunction.writeMapStr_StrDou(WIKI_CF_Map, targetPath);
		System.out.println("complete");
		
	}
}
